package studentMapper

import (
	"gorm.io/gorm"
	"time"
)

type Student struct {
	Id   string `form:"id" json:"id" binding:"required"`
	Name string `form:"name" json:"name" binding:"required"`
	Sex  string `form:"sex" json:"sex" binding:"required"`
	// 映射到表字段为create_time
	CreateTime time.Time
}

func Save(student Student, db *gorm.DB) *gorm.DB {
	return db.Create(student)
}
func UpdateById(student Student, db *gorm.DB) {
	var updateStu Student
	updateStu.Id = student.Id
	// 通过id，更新对象信息
	db.Model(&updateStu).Updates(Student{Name: student.Name, Sex: student.Sex})
}
func DeleteById(db *gorm.DB, id string) {
	var updateStu Student
	updateStu.Id = id
	db.Delete(&updateStu)
}

func GetId(id string, db *gorm.DB) Student {
	var student Student
	db.Where("id = ?", id).First(&student)
	return student
}
